package com.catherine.mvp_base_component.app;

import android.content.Context;

import com.catherine.mvp_base_component.BuildConfig;
import com.catherine.mvp_base_component.base.BaseRetrofitConfig;
import com.catherine.mvp_base_component.utils.ActivityUtil;
import com.catherine.mvp_base_component.realm.RealmKeyUtils;
import com.catherine.mvp_base_component.utils.LogUtil;
import com.catherine.mvp_base_component.utils.ShowUtil;

import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;

/**
 * @Description: 基类application
 * @Author: hhh
 * @CreateDate: 2020/9/15
 */
public abstract class BaseApplication extends MultiDexApplication {

    private static Context mContext;//上下文
    private String mOnlyBaseUrl = "";
    private String mEthBaseUrl = "";
    private String mPhpBaseUrl = "";

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
        MultiDex.install(this);
        initConfig();
        //数据库
        RealmKeyUtils.setInitWalletOCRealm();
    }

    public static Context getAppContext() {
        return mContext;
    }

    /**
     * 初始化 application
     */
    public void initConfig() {
        //初始化
        ShowUtil.initialize(this);
        //设置打印开关
//        LogUtil.setIsLog(BuildConfig.DEBUG);
        LogUtil.setIsLog(BuildConfig.DEBUG);
        //注册Activity生命周期
        registerActivityLifecycleCallbacks(ActivityUtil.getMyActivityLifeCycleCallBack());
        mOnlyBaseUrl = initOnlyBaseUrl();
        mEthBaseUrl = initEthBaseUrl();
        mPhpBaseUrl = initPhpBaseUrl();
        BaseRetrofitConfig.setBaseUrl(mOnlyBaseUrl,mEthBaseUrl,mPhpBaseUrl);
    }

    public abstract String initPhpBaseUrl();
    public abstract String initOnlyBaseUrl();
    public abstract String initEthBaseUrl();
}
